package smedi.ismedi.web.bff.controller.report;

import com.smedi.ismedi.report.api.feign.RemoteReportTrackFeignApi;
import com.smedi.ismedi.report.api.model.ReportTrack;
import com.smedi.ismedi.report.api.model.vo.ReportTrackExportVo;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Api(tags = {"资料管理-目标工程质量追踪"})
@RequestMapping(value = "/webbff/v1/track")
@RestController
public class RemoteReportTrackController {

    @Autowired
    RemoteReportTrackFeignApi remoteReportTrackFeignApi;

    /**
     * 列表查询
     * @return
     */
    @ApiOperation(value = "目标工程质量追踪列表查询", nickname = "目标工程质量追踪列表查询")
    @PostMapping("/list")
    public ResponseData<PaginationData<ReportTrack>> getList(@RequestBody ReportTrack reportTrack){
        return remoteReportTrackFeignApi.getList(reportTrack);
    }

    /**
     * 新增
     * @return
     */
    @ApiOperation(value = "目标工程质量追踪新增", nickname = "目标工程质量追踪新增")
    @PostMapping("/add")
    public ResponseData<String> add(@RequestBody ReportTrack reportTrack){
        return remoteReportTrackFeignApi.add(reportTrack);
    }

    /**
     * 删除
     * @return
     */
    @ApiOperation(value = "目标工程质量追踪删除", nickname = "目标工程质量追踪删除")
    @GetMapping("/delete/{ids}")
    public ResponseData<Boolean> delete(@PathVariable("ids") Long[] trackIds){
        return remoteReportTrackFeignApi.delete(trackIds);
    }

    /**
     * 修改
     * @return
     */
    @ApiOperation(value = "目标工程质量追踪修改", nickname = "目标工程质量追踪修改")
    @PostMapping
    public ResponseData<ReportTrack> edit(@RequestBody ReportTrack reportTrack){
        return remoteReportTrackFeignApi.edit(reportTrack);
    }

    /**
     * 导出
     * @return
     */
    @ApiOperation(value = "目标工程质量追踪导出", nickname = "目标工程质量追踪导出")
    @PostMapping("/exportExcel")
    public void exportAccept(@RequestBody ReportTrackExportVo reportTrack, HttpServletResponse response){
        ResponseData<byte[]> responseData = remoteReportTrackFeignApi.exportAccept(reportTrack);
        try {
            ServletOutputStream outputStream = response.getOutputStream();
            outputStream.write(responseData.getData());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
